package com.kilomob.grady.spring;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * 
 * client解析类
 * 
 *   
 * @author zhouzhixiang  
 * @date 2016年12月31日
 * @since 1.0
 */
public class GradyBeanClientParser implements BeanDefinitionParser {
    public BeanDefinition parse(Element element, ParserContext parserContext) {
        String name = element.getAttribute("name");
        String id = element.getAttribute("id");
        String address = element.getAttribute("address");
        String connections = element.getAttribute("connections");
        String timeout = element.getAttribute("timeout");
        String protocolType = element.getAttribute("protocol");
        String reconnect = element.getAttribute("reconnect");

        RootBeanDefinition beanDefinition = new RootBeanDefinition();
        beanDefinition.setBeanClass(ClientBean.class);
        beanDefinition.getPropertyValues().addPropertyValue("id", id);
        beanDefinition.getPropertyValues().addPropertyValue("address", address);
        beanDefinition.getPropertyValues().addPropertyValue("connections", connections);
        beanDefinition.getPropertyValues().addPropertyValue("timeout", timeout);
        beanDefinition.getPropertyValues().addPropertyValue("name", name);
        beanDefinition.getPropertyValues().addPropertyValue("protocol", protocolType);
        beanDefinition.getPropertyValues().addPropertyValue("reconnect", reconnect);
        parserContext.getRegistry().registerBeanDefinition(name, beanDefinition);

        return beanDefinition;
    }
}


